package com.sunjob.common.feignInterceptor;

import cn.dev33.satoken.stp.StpUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Wangzurong
 * @create 2022-07-24 13:40
 * feign 远程调用时注入satoken
 */
@Component
public class FeignTokenInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        // 获取请求的token
        String tokenVal = StpUtil.getTokenValue();
        // 注入到远程调用的请求头部
        requestTemplate.header("satoken",tokenVal);
    }
}
